import { ajax2 , ajax} from '../../ajax';
// var  getSocket = require("/utils/index.js");

Page({
  data: {
    phone:'',
    password:'',
    deviceNumber:'',
    client_id:'',
    // url:"/login",
    type:1
  },
  getPhone(e) {
    this.setData({
      phone: e.detail.value
    })
  },
  getPassward(e) {
    this.setData({
      password: e.detail.value
    })
  },
  // 登录
  login() {
    let username = this.data.phone;
    let password = this.data.password;
    my.showLoading();
    // let device = my.getStorageSync({ key: 'system' }).data;
    ajax('/login', { username, password }, 'POST').then((res) => {
      let that = this;
      if(res.data.code === 10000) {
        my.hideLoading();
        my.showToast({
          type: 'success',
          content: res.data.message,
          duration: 3000,
          success: () => {
            my.reLaunch({url:'../index/index'});
          },
        });
         my.setStorageSync({key:'token', data:res.data.data.access_token});
      }else{
        my.hideLoading();
        my.showToast({
          type: 'fail',
          content: res.data.message,
          duration: 3000
        });
      }
    }).catch((err) => {
      my.hideLoading();

      console.log(err)
    })
  },
  
  onLoad() {
    console.log('onload')
    let that = this;
   
     
  },
  onShow() {
    let that = this;
  },
   onHide() {
    // my.ix.offKeyEventChange();
    console.log('登录的键盘监听uuuuuuuuuuuuuuu')
  }
});
